package com.weiyi.mashangzhu.Roomer.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.weiyi.mashangzhu.API.API;
import com.weiyi.mashangzhu.R;
import com.weiyi.mashangzhu.Roomer.Bean.AllCommentInfo;
import com.weiyi.mashangzhu.Utils.GlideImgManager;

import java.util.List;

/**
 * Created by win7 on 2017/5/12.
 */

public class AddressAdapter extends BaseAdapter {
    List<String> list;
    Context context;
    String type;
    int num;
    int currentItem;


    public AddressAdapter(List<String> list, Context context, String type, int num,int currentItem) {
        this.list = list;
        this.context = context;
        this.type = type;
        this.num = num;
        this.currentItem=currentItem;
    }
//    public void setSelectedPosition(int position) {
//        selectedPosition = position;
//    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_address, null);
            viewHolder.name = (TextView) convertView.findViewById(R.id.name);
            convertView.setTag(viewHolder);

        }
        viewHolder = (ViewHolder) convertView.getTag();
        switch (num){
            case 1:
                if (position==currentItem){
                    viewHolder.name.setBackgroundColor(context.getResources().getColor(R.color.light_gray_face));
                }else {
                    viewHolder.name.setBackgroundColor(context.getResources().getColor(R.color.white));
                }
                break;
            case 2:
                viewHolder.name.setBackgroundColor(context.getResources().getColor(R.color.light_gray_face));
                break;
            case 3:
                viewHolder.name.setBackgroundColor(context.getResources().getColor(R.color.house_detail_cyan));
                break;
        }
        if (type.equals("yes")){
            if (position==0){
                if (num==1){
                    viewHolder.name.setBackgroundColor(context.getResources().getColor(R.color.light_gray_face));
                }else if (num==2){
                    viewHolder.name.setBackgroundColor(context.getResources().getColor(R.color.house_detail_cyan));
                }

            }
        }


        viewHolder.name.setText(list.get(position)+"");
        return convertView;
    }

    class ViewHolder {
        TextView name;
    }
}
